package com.gxa.ssm251.controller;

import com.gxa.ssm251.exception.BusinessException;
import com.gxa.ssm251.pojo.Cp;
import com.gxa.ssm251.service.CpService;
import com.gxa.ssm251.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

//@Controller("cpController")
//@Controller
@RestController
@RequestMapping("/cp")
@Api(value = "优惠券的管理模块")
public class CpController {

   @Autowired
//    @Resource
   @Qualifier("cpService")
   private CpService cpService;

//   @RequestMapping("/get")
//   public void moximoxi() throws BusinessException {
//        throw new BusinessException("自定义异常");
//   }

   @ApiOperation(value = "根据id查询优惠券的操作",notes = "需要强调的注意事项",
           response = Map.class,httpMethod ="get/post" )
   @ApiImplicitParams(
           @ApiImplicitParam(name = "id",value = "这是优惠券的编号",required = true,
                   dataType = "String",example = "1")
   )
   @PostMapping("/get")
   @ResponseBody
   public JsonResult moximoxi(@RequestParam("cp")Integer id) throws BusinessException {
      JsonResult jsonResult=new JsonResult();
      jsonResult.setCode("1");
      jsonResult.setMsg("查询成功");
      Cp cp=new Cp();
      cp.setId(id);
      cp.setName("冬日优惠券");
      jsonResult.setData(cp);
      return jsonResult;
   }

   @ApiOperation(value = "添加优惠券的操作")
   @ApiImplicitParams(
           @ApiImplicitParam(name = "coupon",value = "json格式的优惠券对象",dataType = "body",format = "formatBody")
   )
   @PostMapping("/add")
   public JsonResult add(@RequestBody Integer id){
      System.out.println(id);
      return null;
   }


   public JsonResult selectByPage(@RequestParam("page") Integer page,@RequestParam("size") Integer size,
                                  @RequestParam(value = "page",required = false)String name){
      return null;
   }


}
